import type { FieldConfig } from '@/components/TableFilter.vue'
import { usePromotionStore } from '@/store/promotionStore'
import { useCustomConsultTypeStore } from '@/store/customConsultTypeStore'

// 表格列配置
export const tableColumns = [
  {
    title: 'ID',
    dataIndex: 'id',
    fixed: 'left'
  },
  {
    title: '發票號',
    dataIndex: 'invNo',
    fixed: 'left'
  },
  {
    title: '店鋪',
    dataIndex: 'shop',
  },
  {
    title: '員工編號',
    dataIndex: 'staffCode',
  },
  {
    title: '醫師姓名',
    dataIndex: 'doctorName',
  },
  {
    title: '會員卡',
    dataIndex: 'pcard',
  },
  {
    title: '定額優惠',
    dataIndex: 'faName',
  },
  {
    title:'是否診症',
    dataIndex:'consultFlag',
  },
  {
    title: '診金歸屬',
    dataIndex: 'consultShareClass',
  },
  {
    title: '類別',
    dataIndex: 'subClassName',
  },
  {
    title: '發票淨額',
    dataIndex: 'invoiceNet',
  },
  {
    title: '交易日期',
    dataIndex: 'invDate',
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
    fixed: 'right',
  },
]
// 過濾項配置
export const filterFields: FieldConfig[] = [
  {
    name: 'inv_no',
    label: '發票號',
    type: 'input',
    placeholder: '請輸入發票號',
  },
  {
    name: 'staff_code',
    label: '員工編號',
    type: 'input',
    placeholder: '請輸入員工編號',
  },
  {
    name: 'doctor_name',
    label: '醫師姓名',
    type: 'input',
    placeholder: '請輸入醫師姓名',
  },
  {
    name: 'inv_date',
    label: '交易日期',
    type: 'range-picker',
    placeholder: ['開始日期', '結束日期'],
  },
  {
    name: 'consult_share_class',
    label: '診金歸屬',
    type: 'select',
    placeholder: '請選擇醫師發票診金歸屬',
    options: [
      { label: '全部', value: '' },
      { label: '默認', value: '0' },
      { label: '推廣活動', value: '1' },
      { label: '自定義', value: '2' },
      { label: '指定服務', value: '3' },
    ],
  },
  {
    name: 'consult_share_promotion_id',
    label: '推廣活動',
    type: 'select',
    placeholder: '請選擇推廣活動',
    options: [],
  },
  {
    name: 'custom_consult_type',
    label: '自定義診金類型',
    type: 'select',
    placeholder: '請選擇自定義診金類型',
    options: [],
  },
  {
    name: 'specify_service_type',
    label: '指定服務類型',
    type: 'select',
    placeholder: '請選擇自定義診金類型',
    options: [
      { label: '全部', value: '' },
      { label: '專科', value: '1' },
      { label: '月子中心', value: '2' },
    ],
  },
  {
    label: '是否退單',
    name: 'is_refund',
    type: 'select',
    options: [
      { label: '全部', value: '' },
      { label: '是', value: '1' },
      { label: '否', value: '0' },
    ],
  },
]

export const getProcessFilterFields = async () => {
  const promotionOptions = await usePromotionStore().fetchOptions()
  const promotionField = filterFields.find((item) => item.name == 'consult_share_promotion_id')
  if (promotionField) {
    promotionField.options = promotionOptions
  }
  const customConsultTypeOptions = await useCustomConsultTypeStore().fetchOptions()
  const customConsultTypeField = filterFields.find((item) => item.name == 'custom_consult_type')

  if (customConsultTypeField) {
    customConsultTypeField.options = customConsultTypeOptions.filter((item) => item.value > 0)
    customConsultTypeField.options.unshift({
      label: '全部',
      value: '',
    })
  }
  return filterFields
}
